package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.customdo.ProjectADO;
import com.smart.model.domain.ProjectDO;
import com.smart.model.domain.ProjectFileTaskDO;
import com.smart.model.request.ProjectFileTaskRequest;
import com.smart.model.vo.ProjectVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface ProjectFileTaskMapper extends BaseMapper<ProjectFileTaskDO> {
    ProjectFileTaskDO selectDOById(Long id);
    List<ProjectFileTaskDO> selectDOList(ProjectFileTaskDO projectFileTask);
    int insertDO(ProjectFileTaskDO projectFileTask);
    int batchInsertDO(List<ProjectFileTaskDO> projectFileTaskDOList);
    int updateDO(ProjectFileTaskDO projectFileTask);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from project_file_task",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.keyWord!=null and param.keyWord!=''\">",
            "           and (file_name like concat('%',#{param.keyWord},'%') or file_code = #{param.keyWord})",
            "       </if>",
            "       <if test=\"param.fileStatus!=null and param.fileStatus!=''\">and file_status=#{param.fileStatus}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ProjectFileTaskRequest param);
    @Select({"<script>",
            "   select * from project_file_task",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.keyWord!=null and param.keyWord!=''\">",
            "           and (file_name like concat('%',#{param.keyWord},'%') or file_code = #{param.keyWord})",
            "       </if>",
            "       <if test=\"param.fileStatus!=null and param.fileStatus!=''\">and file_status=#{param.fileStatus}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ProjectFileTaskDO> pageQuery(@Param("param") ProjectFileTaskRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Select("select * from project_file_task order by file_date desc, file_num desc limit 1")
    ProjectFileTaskDO getRecentOne();

    long countProjectByCondition(@Param("param") ProjectFileTaskRequest request);
    List<ProjectADO> pageProjectByCondition(@Param("param") ProjectFileTaskRequest request, @Param("limit") int limit, @Param("offset") long offset);
    List<ProjectADO> listProjectByCondition(@Param("param") ProjectFileTaskRequest request);

    Long getUnReceive(Long projectId);

}
